package com.sync.utils.common.validation.annotation.impl;

import com.sync.utils.common.validation.annotation.StrictEmail;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * 自定义邮件号校验逻辑
 *
 * @Author YWF
 * @Date 2025/5/8 17:01
 */
public class StrictEmailValidator implements ConstraintValidator<StrictEmail,String> {

    private static final Pattern EMAIL_PATTERN =
            Pattern.compile("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$");
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null){
            return true; // 配合 @NotNull 使用
        }
        return EMAIL_PATTERN.matcher(value).matches();
    }
}
